<template>
  <div style="height:85px;">
    <div>
      <el-row style="background-color: #34495e;opacity:0.85;height: 85px" >
        <el-col>
          <div class="header-main" >
            <el-row :span="25" type="flex" justify="space-between" style="height: 85px">
              <el-col :span="1">
                  <el-image :src="require('@/assets/icon1.png')" style="padding-top: 10px"></el-image>
                  <span style="color:#D9CCDE;font-size: 20px;position: absolute;margin-top: 30px;padding-left: 10px;">调查问卷系统</span>
              </el-col>
              <el-col :span="2" style="text-align:center;padding-top: 10px" >
                <el-icon size="25px" color="white"><Avatar/></el-icon>
                <div>
                  <el-dropdown @command="handleCommand">
                    <span class="el-dropdown-link" >
                      {{ userName }} <i class="el-icon-arrow-down el-icon--right"></i>
                    </span>
                    <template v-slot:dropdown>
                      <el-dropdown-menu >
                        <el-dropdown-item command="myAccount">我的账号</el-dropdown-item>
                        <el-dropdown-item command="updatePwd">修改密码</el-dropdown-item>
                        <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                      </el-dropdown-menu>
                    </template>
                  </el-dropdown>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
export default {
  name: "SHeader",
  data(){
    return{
      userName:'',
      isAdmin:'',
      isTenant:'',
      isUser:''
    }
  },
  methods:{
    handleCommand: function (command) {
      if(command==='logout'){
        this.$axios.post('/logout',{
          headers:{
            Authorization: localStorage.getItem("userInfo")
          }
        });
      }else if(command==='myAccount'){
        this.$router.push('/MyInfo')
      }
      // if (command === 'logout') {
      //   logout().then(() => {
      //     this.$router.push('/Login');
      //   })
      // // } else if (command === 'myAccount') {
      //   this.$router.push('/dw/user')
      // } else if (command === 'updatePwd') {
      //   this.$router.push('/dw/user/pwd')
      // }
    },
    judgement(){
      if(this.$store.getters.getUser.data.permission==0){
          this.userName=this.$store.getters.getUser.data.username+"(系统管理员)",
              this.isAdmin=true,
              this.isTenant=false,
              this.isUser=false
      }else if(this.$store.getters.getUser.data.permission==1){
        this.userName=this.$store.getters.getUser.data.username+"(租户)",
            this.isTenant=true,
            this.isAdmin=false,
            this.isUser=false
      }else{
            this.userName=this.$store.getters.getUser.data.username+"(用户)",
            this.isTenant=false,
            this.isAdmin=false,
            this.isUser=true
      }
    },
  },
  beforeMount() {
    this.judgement()
  }
}
</script>

<style scoped>
.header-main{
}
.el-dropdown-link{
  color: white;
  font-size: 15px;
}
.m-logbg {
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>